package com.smdp.controller;


import com.smdp.dto.Result;
import com.smdp.service.IVoucherOrderService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 优惠券订单前端控制器。
 * 包含获取普通券和尝试获取秒杀券。
 *
 * @author 蔡方珩
 */
@RestController
@RequestMapping("/voucher-order")
public class VoucherOrderController {
    @Resource
    private IVoucherOrderService voucherOrderService;

    /**
     * 尝试获取秒杀券
     * @param voucherId 秒杀券id
     * @return 成功：orderId / 失败：失败原因
     */
    @PostMapping("/seckill/{id}")
    public Result seckillVoucher(@PathVariable("id") Long voucherId) {
        return voucherOrderService.getSeckillVoucher(voucherId);
    }

    /**
     * 获取普通券
     * @param voucherId 普通券id
     * @return 成功：orderId / 失败：失败原因
     */
    @PostMapping("/{id}")
    public Result voucher(@PathVariable("id") Long voucherId) {
        return voucherOrderService.getVoucher(voucherId);
    }
}
